package cn.edu.neusoft.model.impl;

import cn.edu.neusoft.model.bean.User;
import cn.edu.neusoft.model.mapper.UserMapper;
import cn.edu.neusoft.service.car.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class PeoleInfoImpl {
    @Autowired
    private PeopleInfoHandler peopleInfoHandler;
    @Autowired
    private UserMapper userMapper;
    public void restoreAllPeoples(){
        int pageNum = 0;
        int total = 0;
        GetAllPeopleRequest getAllPeopleRequest = new GetAllPeopleRequest();

        GetAllPeopleResponse allPeopleResponse = null;
        userMapper.truncateTable();
        do
        {
            getAllPeopleRequest.setPageNum(++pageNum);
            allPeopleResponse = peopleInfoHandler.getPeopleInfoByPage(getAllPeopleRequest);
            for (User pageDatum : allPeopleResponse.getData().getPageData()) {
                userMapper.insertUser(pageDatum);
                total++;
            }

            log.info("PeoleInfoImpl,restoreAllPeoples,pagenum:{},total:{}", pageNum,total);
        }while(allPeopleResponse != null && allPeopleResponse.getData().getCurrentPage() < allPeopleResponse.getData().getTotalPage() );
    }
}
